#include <stdio.h>
#include <string.h>
#include <libgen.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
int  get_pid(char *proname)
{
    FILE            *fp = NULL;
    char            command[150];
    char            buf[300];
    int             pid = -1;
    // snprintf(command, sizeof(command), "ps -ef | grep -w %s | grep -v 'grep' | awk '{print $2}'", proname);  //awk方式
    snprintf(command, sizeof(command), "ps -C %s -o pid=", proname);
    fp=popen(command, "r");
    if( !fp )
    {       
        printf("pepen errno\n");
        return -1;
    }

    if((fgets(buf, sizeof(buf), fp)) != NULL)
    {
        pid = atoi(buf);
        printf("%d\n", pid);
    }
    pclose(fp);
    fp = NULL;

    return pid;
}
int   main(int argc, char **argv)
{
    int pid = get_pid("xfrpc_pc");
    printf("pid is %d\n", pid);
    if(kill(pid, SIGABRT) < 0) printf("kill failed\n");
    
    
}
